﻿using System;
/*
 * User: RSny
 * Date: 5/16/2012
 * Time: 2:18 PM
 */

namespace Aspects.Custom.Audio
{
    public class SineWaveProvider : IWaveProvider
    {
        public WaveFormat waveFormat
        {
            get {return _waveFormat;}
            set {_waveFormat = value;}
        }
        public float Frequency { get; set; }
        public float Amplitude { get{return _amplitude;} set{_amplitude = value * short.MaxValue;} }
        private float _amplitude;
        public int Read(byte[] buffer, int offset, int count)
        {
            short[] sineWaveBuffer = new short[buffer.Length/2];
            for (int i = 0; i < sineWaveBuffer.Length; i++)
            {
                sineWaveBuffer[i] = (short)(Amplitude * Math.Sin((2 * Math.PI * i * Frequency) / waveFormat.nSamplesPerSec));
            }
            Buffer.BlockCopy(sineWaveBuffer, 0, buffer, 0, buffer.Length);
            return count;
        }
        private WaveFormat _waveFormat = new WaveFormat(16000, 16, 1);
    }
}